package com.design.singleton;

import java.util.ArrayList;

/**
 * 内部枚举类实现单例模式
 */
public class SingletonExample7 {
    private SingletonExample7(){}

    public enum SingletonExample7Enum{
        INSTANCE;

        private SingletonExample7 singletonExample7;

        //枚举类的构造方法，JVM保证这个方法绝对只调用一次
        SingletonExample7Enum(){
            singletonExample7 = new SingletonExample7();
        }

        public SingletonExample7 getInstance(){
            return singletonExample7;
        }
    }

    public static void main(String[] args) {
        System.out.println(SingletonExample7Enum.INSTANCE.getInstance());
        System.out.println(SingletonExample7Enum.INSTANCE.singletonExample7);

        new ArrayList<String>();
    }
}
